package com.example.testandroid;

import android.app.Activity;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

import java.util.Random;


public class MainActivity extends AppCompatActivity {
    public Button button;
    public String s = "弹出提示";
    public static String t1 = "show tip 111";
    public static char c = 'a';
    public static  int num  = 1;
    private int count = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Context t = (Context)MainActivity.this;

        button = (Button)findViewById(R.id.button);
        button.setOnClickListener( new ClickBtn1CallFun());

        Button btn2 = (Button)findViewById(R.id.button2);
        btn2.setOnClickListener(new ClickBtn2Listener());

        Button btn3 = (Button)findViewById(R.id.button3);
        btn3.setOnClickListener(new ClickBtn3Listener());

        Button btn4 = (Button)findViewById(R.id.button4);
        btn4.setOnClickListener(new Button4ClickEventer());

        Button btn5 = (Button)findViewById(R.id.button5);
        btn5.setOnClickListener(new Button5ClickEventer());

        Button btn6 = (Button)findViewById(R.id.button6);
        btn6.setOnClickListener(new Button6ClickEventer());

        Button btn7 = (Button)findViewById(R.id.button7);
        btn7.setOnClickListener(new Button7ClickEventer());

    }

    private class ClickBtn2Listener implements View.OnClickListener{

        @Override
        public void onClick(View view) {
            String t = ""+ c;
//            Toast.makeText(MainActivity.this, t, Toast.LENGTH_SHORT).show();
            MainActivity.this.addmore(num);
        }
    }

    public class ClickBtn3Listener implements View.OnClickListener{

        @Override
        public void onClick(View view) {
            TextView v = (TextView) findViewById(R.id.tview);
            num++;
            Integer Numb = new Integer(num);
            v.setText(Numb.toString());
        }
    }
    public class ClickBtn1CallFun implements View.OnClickListener{

        @Override
        public void onClick(View view) {
            num++;
            MainActivity.this.showArgs(num);
        }
    }
    public class Button4ClickEventer implements View.OnClickListener{

        @Override
        public void onClick(View view) {
            MainActivity.this.showClick4(count);
        }
    }
    public class Button5ClickEventer implements View.OnClickListener{

        @Override
        public void onClick(View view) {
            Toast.makeText(MainActivity.this, "5", Toast.LENGTH_SHORT).show();

        }
    }
    public class Button6ClickEventer implements View.OnClickListener{

        @Override
        public void onClick(View view) {
            Toast.makeText(MainActivity.this, "6", Toast.LENGTH_SHORT).show();

        }
    }

    public class Button7ClickEventer implements View.OnClickListener{

        @Override
        public void onClick(View view) {
            Utils u = new Utils();
            Random r = new Random();
            int n = r.nextInt(100) + 1;
            int fangdan = u.Fangda(n);
            Toast.makeText(MainActivity.this, ""+fangdan, Toast.LENGTH_SHORT).show();

        }
    }

    private void showArgs(int a){
        Integer n = new Integer(a);
        Toast.makeText(MainActivity.this,n.toString(), Toast.LENGTH_SHORT).show();
    }

    public  void addmore(int a){
        Integer n = new Integer(a);
        Toast.makeText(MainActivity.this,"add-- more ::::"+n.toString(), Toast.LENGTH_SHORT).show();
    }

    public int newint(int a){
        return  a*100;
    }
    private void showClick4(int n){
        Toast.makeText(MainActivity.this, "click4  = "  + new Integer(n).toString(), Toast.LENGTH_SHORT).show();

    }
}
